
import sys
import random
import time

def main(length):

    print 'length is ', length

    length = int(length)

    # initailize postiztion
    post = [' '] * (length + 1)
    post[0] = '~'
    post[length] = '|'

    orig_x = length / 2
    #orig_y = 0

    count = 0
    
    #start_time = time.asctime()

    #print 'begin...'
    #print 'begin time: ', start_time

    while 1:
        post[orig_x] = '+'
        print '[steps %5s]' %count, ''.join(post)
        post[orig_x] = ' '

        count += 1
        r = random.randrange(2)
        # try this to have more random numbers
        if r == 0:
            # walk a step right to wall
            orig_x += 1
            if orig_x == length:
                orig_x -= 1
        elif r == 1:
            # walk a step left
            orig_x -= 1
            if orig_x == 0:
                break
    
    post[orig_x] = '*'
    print '[steps %5s]' %count, ''.join(post)

    """
        elif r == 2:
            # walk a step fowrad
            orig_y += 1
        if orig_x >= length or orig_x <= 0 or orig_y >= length:
            break
    
        print 'start time... ' , start_time
        print 'time now... ' , time.asctime()
        print 'tried times... ', count
        print 'location... ', orig_x, orig_y
        print 
    
    print 'I ticked a wall!'
    print 'tried %s times' %count
    print 'start time', start_time
    print 'end time: ' , time.asctime()
    """

if __name__ == '__main__':
    print sys.exit(main(sys.argv[1]))
